<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>插入数据</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
</head>
<body>
    <?php 
    //echo $_GET['id'];
    require_once "conn.php";

        if(count($_POST)>0) {
        mysqli_query($link,"UPDATE users set name='" . $_POST['username'] . "',
        mobile='" . $_POST['mobile'] . "' ,email='" . $_POST['email'] . "' WHERE id='" . $_POST['id'] . "'");
        header("location: index.php");
        exit();
        }
       

        $result = mysqli_query( $link,"SELECT * FROM users WHERE id='" . $_GET['id'] . "'");
        $row=mysqli_fetch_array($result);

?>
    <div class="container mt-4">
        <div class="row justify-content-center">
            <div class="col-sm-8">
                <h2>修改记录</h2>
                <form action="" method="post">
                    <div class="form-group">
                        <label for="username">姓名</label>
                        <input type="text" class="form-control" id="username" name="username" value="<?php echo $row['name'];?>">
                    </div>
                    <div class="form-group">
                        <label for="email">邮箱</label>
                        <input type="text" class="form-control" id="email" name="email" value="<?php echo $row['email'];?>">
                    </div>
                    <div class="form-group">
                        <label for="mobile">电话号码</label>
                        <input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo $row['mobile'];?>">
                    </div>
                    <input type="hidden" name="id" value="<?php echo $row['id'];?>">
                    <button type="submit" class="btn btn-primary" name="save">修改</button>
                    <a class="btn btn-success" href="./index.php">返回首页</a>
                  </form>

            </div>
        </div>
    </div>
   
    
</body>
</html>